<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="hg-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="stylesheet" href="/hg-layui-admin-ui/css/font.css">
    <link rel="stylesheet" href="/hg-layui-admin-ui/lib/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/hg-layui-admin-ui/lib/admin/admin.css" media="all">
    <link rel="stylesheet" href="/hg-layui-admin-ui/lib/Scrollbar/jquery.scrollbar.css">
    <script type="text/javascript" src="/hg-layui-admin-ui/lib/admin/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="/hg-layui-admin-ui/lib/Scrollbar/jquery.scrollBar.js"></script>
    <script type="text/javascript" src="/hg-layui-admin-ui/lib/layui/layui.js"></script>
    <script type="text/javascript" src="/hg-layui-admin-ui/lib/admin/admin.js"></script>
    <style>


    </style>
</head>
<body>
    <form class="layui-form layui-row changePwd" id="setpwd" style="margin-top: 5%;">
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
            <div class="layui-input-block layui-red pwdTips"  style="color: red">旧，新密码必须两次输入一致才能提交</div>
            <div class="layui-form-item">
                <label class="layui-form-label">旧密码</label>
                <div class="layui-input-block">
                    <input type="password" value="" placeholder="请输入旧密码" lay-verify="required|oldPwd"  id="pwd"  class="layui-input pwd">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">新密码</label>
                <div class="layui-input-block">
                    <input type="password" value="" placeholder="请输入新密码" lay-verify="required|newPwd" id="oldPwd" class="layui-input pwd">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">确认密码</label>
                <div class="layui-input-block">
                    <input type="password" value="" placeholder="请确认密码" lay-verify="required|confirmPwd" id="newpwd" class="layui-input pwd">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="changePwd" >立即修改</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </div>
    </form>
</body>
</html>
<script>

    layui.use([ 'form', 'layer', 'laydate', 'table', 'laytpl' ],function(){
        var layer = layui.layer;
        form.on('submit(changePwd)', function(data) {
            if ($("#oldPwd").val().length < 6) {
                layer.msg("密码长度不能小于6位");
                return  false;
            }
            //老密码
            var pwd = $("#pwd").val();
            //新密码1
            var oldpwd = $("#oldPwd").val();
            //新密码2
            var newpwd = $("#newpwd").val();
            if (oldpwd != newpwd) {
                layer.msg("两次输入密码不一致，请重新输入！");
                return  false;
            }
            $.ajax({
                type:"POST",
                url:"/admin/user/setPsw",
                data:{"oldpsw":pwd,"newpsw":newpwd},
                dataType:"json",
                async : true, //是否异步
                success:function (data) {
                    console.log("dayin");
                    console.log(data);
                    if(data==false){
                        layer.msg("旧密码不正确！");
                    }else{
                        layer.msg('提示：修改密码成功！请重新登录');
                        setTimeout(function(){
                            window.parent.location="/login";
                        },1000)
                    }
                },
                error: function (data,type, err) {
                    console.log("ajax错误类型："+type);
                    console.log(err);
                    hg.msg('删除失败！');
                }
            });
            return false;
        });

    })



</script>